package com.zgm.utils.ui;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zgm.utils.R;

/**
 * Created by 张公铭 on 2017/8/8 0008.
 */

public class UiTextHeader extends LinearLayout
{
    private Context mContext;
    private View view_bar;
    private ImageView iv_left;
    private RelativeLayout rl_root;
    private TextView tv_title;
    private TextView tv_right_text;

    public UiTextHeader(Context context)
    {
        this(context, null);
    }

    public UiTextHeader(Context context, @Nullable AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public UiTextHeader(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
        mContext = context;
        init();
    }

    private void init()
    {
        LayoutInflater.from(mContext).inflate(R.layout.text_header, this);
        view_bar = findViewById(R.id.view_text_header_bar);
        iv_left = (ImageView) findViewById(R.id.iv_text_header_left);
        rl_root = (RelativeLayout) findViewById(R.id.rl_text_header_root);
        tv_title = (TextView) findViewById(R.id.tv_text_header_title);
        tv_right_text = (TextView) findViewById(R.id.tv_text_header_right_desc);
    }

    public void setBarHeight(int height)
    {
        ViewGroup.LayoutParams params = view_bar.getLayoutParams();
        params.height = height;
        view_bar.setLayoutParams(params);
        view_bar.setVisibility(VISIBLE);
    }

    public void setBackgroundColor(String color)
    {
        rl_root.setBackgroundColor(Color.parseColor(color));
    }


    /**
     * 设置左边按钮事件
     *
     * @param listener
     */
    public void setLeftButtonOnClickListener(OnClickListener listener)
    {
        iv_left.setOnClickListener(listener);
    }

    public void hindLeftButton()
    {
        iv_left.setVisibility(GONE);
    }

    public void setLeftBottonIcon(int resId)
    {
        iv_left.setImageResource(resId);
    }

    public void setTitle(String text)
    {
        tv_title.setText(text);
    }

    public void setTitleStyle(int resId)
    {
        tv_title.setTextAppearance(mContext, resId);
    }

    public void setTitleColor(String color)
    {
        tv_title.setTextColor(Color.parseColor(color));
    }

    public void setTitleBk(int resId)
    {
        tv_title.setBackgroundResource(resId);
    }

    public void setRightText(String text)
    {
        tv_right_text.setText(text);
    }

    public void setRightTextColor(String color)
    {
        tv_right_text.setTextColor(Color.parseColor(color));
    }

    public void setRightTextListener(OnClickListener listener)
    {
        tv_right_text.setOnClickListener(listener);
    }

    public void hindRight()
    {
        tv_right_text.setVisibility(GONE);
    }
}
